<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="公司ID" prop="companyId">
        <el-input
          v-model="queryParams.companyId"
          placeholder="请输入公司ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门ID" prop="dpmId">
        <el-input
          v-model="queryParams.dpmId"
          placeholder="请输入部门ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="UserID" prop="userid">
        <el-input
          v-model="queryParams.userid"
          placeholder="请输入UserID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input
          v-model="queryParams.password"
          placeholder="请输入密码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职务信息" prop="position">
        <el-input
          v-model="queryParams.position"
          placeholder="请输入职务信息"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <el-input
          v-model="queryParams.gender"
          placeholder="请输入性别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="头像" prop="avatar">
        <el-input
          v-model="queryParams.avatar"
          placeholder="请输入头像"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="座机" prop="telephone">
        <el-input
          v-model="queryParams.telephone"
          placeholder="请输入座机"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="启用状态" prop="enable">
        <el-input
          v-model="queryParams.enable"
          placeholder="请输入启用状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="别名" prop="alias">
        <el-input
          v-model="queryParams.alias"
          placeholder="请输入别名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="二维码" prop="qrCode">
        <el-input
          v-model="queryParams.qrCode"
          placeholder="请输入二维码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="对外职务" prop="externalPosition">
        <el-input
          v-model="queryParams.externalPosition"
          placeholder="请输入对外职务"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数据来源" prop="sources">
        <el-input
          v-model="queryParams.sources"
          placeholder="请输入数据来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账号关联" prop="assId">
        <el-input
          v-model="queryParams.assId"
          placeholder="请输入账号关联"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="OpenId" prop="openid">
        <el-input
          v-model="queryParams.openid"
          placeholder="请输入OpenId"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="员工编号" prop="employeeId">
        <el-input
          v-model="queryParams.employeeId"
          placeholder="请输入员工编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除时间" prop="deletedAt">
        <el-date-picker clearable
          v-model="queryParams.deletedAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择删除时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="创建时间" prop="createdAt">
        <el-date-picker clearable
          v-model="queryParams.createdAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新时间" prop="updatedAt">
        <el-date-picker clearable
          v-model="queryParams.updatedAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="3" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['admin:corp_company_users:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['admin:corp_company_users:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['admin:corp_company_users:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['admin:corp_company_users:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="corp_company_usersList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="公司ID" align="center" prop="corpCompanies.corpName" />
      <el-table-column label="部门ID" align="center" prop="dpmId" />
      <el-table-column label="排序" align="center" prop="order" />
      <el-table-column label="部门领导" align="center" prop="isLeaderInDept" />
      <el-table-column label="UserID" width="90" align="center" prop="userid" />
      <el-table-column label="名称" width="90" align="center" prop="name" />
      <el-table-column label="密码" width="170" :show-overflow-tooltip="true" align="center" prop="password" />
      <el-table-column label="职务信息" align="center" prop="position" />
      <el-table-column label="手机号码" align="center" prop="mobile" />
      <el-table-column label="性别" align="center" prop="gender" />
      <el-table-column label="邮箱" align="center" prop="email" />
      <el-table-column label="头像" width="170" :show-overflow-tooltip="true" align="center" prop="avatar" />
      <el-table-column label="座机" align="center" prop="telephone" />
      <el-table-column label="启用状态" align="center" prop="enable" />
      <el-table-column label="别名" align="center" prop="alias" />
      <el-table-column label="激活状态" align="center" prop="status" />
      <el-table-column label="扩展属性" align="center" prop="extattr" />
      <el-table-column label="二维码" align="center" prop="qrCode" />
      <el-table-column label="对外职务" align="center" prop="externalPosition" />
      <el-table-column label="地址" align="center" prop="address" />
      <el-table-column label="对外属性" align="center" prop="externalProfile" />
      <el-table-column label="数据来源" align="center" prop="sources" />
      <el-table-column label="账号关联" align="center" prop="assId" />
      <el-table-column label="用户状态" align="center" prop="woStatus" />
      <el-table-column label="OpenId" align="center" prop="openid" />
      <el-table-column label="员工编号" align="center" prop="employeeId" />
      <el-table-column label="删除时间" align="center" prop="deletedAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deletedAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createdAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updatedAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatedAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" width="110px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['admin:corp_company_users:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['admin:corp_company_users:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户列对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="公司ID" prop="companyId">
          <el-input v-model="form.companyId" placeholder="请输入公司ID" />
        </el-form-item>
        <el-form-item label="部门ID" prop="dpmId">
          <el-input v-model="form.dpmId" placeholder="请输入部门ID" />
        </el-form-item>
        <el-form-item label="UserID" prop="userid">
          <el-input v-model="form.userid" placeholder="请输入UserID" />
        </el-form-item>
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="form.password" placeholder="请输入密码" />
        </el-form-item>
        <el-form-item label="职务信息" prop="position">
          <el-input v-model="form.position" placeholder="请输入职务信息" />
        </el-form-item>
        <el-form-item label="手机号码" prop="mobile">
          <el-input v-model="form.mobile" placeholder="请输入手机号码" />
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-input v-model="form.gender" placeholder="请输入性别" />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="头像" prop="avatar">
          <el-input v-model="form.avatar" placeholder="请输入头像" />
        </el-form-item>
        <el-form-item label="座机" prop="telephone">
          <el-input v-model="form.telephone" placeholder="请输入座机" />
        </el-form-item>
        <el-form-item label="启用状态" prop="enable">
          <el-input v-model="form.enable" placeholder="请输入启用状态" />
        </el-form-item>
        <el-form-item label="别名" prop="alias">
          <el-input v-model="form.alias" placeholder="请输入别名" />
        </el-form-item>
        <el-form-item label="二维码" prop="qrCode">
          <el-input v-model="form.qrCode" placeholder="请输入二维码" />
        </el-form-item>
        <el-form-item label="对外职务" prop="externalPosition">
          <el-input v-model="form.externalPosition" placeholder="请输入对外职务" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="对外属性">
          <file-upload v-model="form.externalProfile"/>
        </el-form-item>
        <el-form-item label="数据来源" prop="sources">
          <el-input v-model="form.sources" placeholder="请输入数据来源" />
        </el-form-item>
        <el-form-item label="账号关联" prop="assId">
          <el-input v-model="form.assId" placeholder="请输入账号关联" />
        </el-form-item>
        <el-form-item label="OpenId" prop="openid">
          <el-input v-model="form.openid" placeholder="请输入OpenId" />
        </el-form-item>
        <el-form-item label="员工编号" prop="employeeId">
          <el-input v-model="form.employeeId" placeholder="请输入员工编号" />
        </el-form-item>
        <el-form-item label="删除时间" prop="deletedAt">
          <el-date-picker clearable
            v-model="form.deletedAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择删除时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建时间" prop="createdAt">
          <el-date-picker clearable
            v-model="form.createdAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新时间" prop="updatedAt">
          <el-date-picker clearable
            v-model="form.updatedAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择更新时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCorp_company_users, getCorp_company_users, delCorp_company_users, addCorp_company_users, updateCorp_company_users } from "@/api/admin/corp_company_users";

export default {
  name: "Corp_company_users",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 用户列表格数据
      corp_company_usersList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyId: null,
        dpmId: null,
        order: null,
        isLeaderInDept: null,
        userid: null,
        name: null,
        password: null,
        position: null,
        mobile: null,
        gender: null,
        email: null,
        avatar: null,
        telephone: null,
        enable: null,
        alias: null,
        status: null,
        extattr: null,
        qrCode: null,
        externalPosition: null,
        address: null,
        externalProfile: null,
        sources: null,
        assId: null,
        woStatus: null,
        openid: null,
        employeeId: null,
        deletedAt: null,
        createdAt: null,
        updatedAt: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        companyId: [
          { required: true, message: "公司ID不能为空", trigger: "blur" }
        ],
        userid: [
          { required: true, message: "UserID不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "名称不能为空", trigger: "blur" }
        ],
        password: [
          { required: true, message: "密码不能为空", trigger: "blur" }
        ],
        position: [
          { required: true, message: "职务信息不能为空", trigger: "blur" }
        ],
        mobile: [
          { required: true, message: "手机号码不能为空", trigger: "blur" }
        ],
        gender: [
          { required: true, message: "性别不能为空", trigger: "blur" }
        ],
        email: [
          { required: true, message: "邮箱不能为空", trigger: "blur" }
        ],
        avatar: [
          { required: true, message: "头像不能为空", trigger: "blur" }
        ],
        telephone: [
          { required: true, message: "座机不能为空", trigger: "blur" }
        ],
        enable: [
          { required: true, message: "启用状态不能为空", trigger: "blur" }
        ],
        alias: [
          { required: true, message: "别名不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "激活状态不能为空", trigger: "blur" }
        ],
        qrCode: [
          { required: true, message: "二维码不能为空", trigger: "blur" }
        ],
        externalPosition: [
          { required: true, message: "对外职务不能为空", trigger: "blur" }
        ],
        address: [
          { required: true, message: "地址不能为空", trigger: "blur" }
        ],
        assId: [
          { required: true, message: "账号关联不能为空", trigger: "blur" }
        ],
        woStatus: [
          { required: true, message: "用户状态不能为空", trigger: "blur" }
        ],
        openid: [
          { required: true, message: "OpenId不能为空", trigger: "blur" }
        ],
        employeeId: [
          { required: true, message: "员工编号不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户列列表 */
    getList() {
      this.loading = true;
      listCorp_company_users(this.queryParams).then(response => {
        this.corp_company_usersList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        companyId: null,
        dpmId: null,
        order: null,
        isLeaderInDept: null,
        userid: null,
        name: null,
        password: null,
        position: null,
        mobile: null,
        gender: null,
        email: null,
        avatar: null,
        telephone: null,
        enable: null,
        alias: null,
        status: 0,
        extattr: null,
        qrCode: null,
        externalPosition: null,
        address: null,
        externalProfile: null,
        sources: null,
        assId: null,
        woStatus: 0,
        openid: null,
        employeeId: null,
        deletedAt: null,
        createdAt: null,
        updatedAt: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户列";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCorp_company_users(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户列";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCorp_company_users(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCorp_company_users(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除用户列编号为"' + ids + '"的数据项？').then(function() {
        return delCorp_company_users(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('admin/corp_company_users/export', {
        ...this.queryParams
      }, `corp_company_users_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
.el-form-item--small.el-form-item{
  margin-bottom: 10px;
}
/deep/ label{
  font-weight: 500;
}
/deep/ .el-date-editor.el-input, .el-date-editor.el-input__inner {
  width: 215px;
}
</style>
